package com.ujs.edu.demo.dao;

import com.ujs.edu.demo.dataobject.BcBooks;
import org.apache.ibatis.jdbc.SQL;

public class BookBuildQuery {

    public String queryBuiler(BcBooks bcBooks){
        return new SQL(){
            {
                SELECT("book_id, book_name, book_num, brief, description, makt_able, cart_id, createtime, modifytime, author, cover, memberId");
                FROM("bc_books");
                if (bcBooks.getBookName()!=null){
                    WHERE("book_name like concat('%',#{bcBooks.bookName},'%')");
                }else if (bcBooks.getBookNum()!=null){
                    WHERE("book_num like concat('%',#{bcBooks.bookNum},'%')");
                }else if (bcBooks.getAuthor()!=null){
                    WHERE("author like concat('%',#{bcBooks.author},'%')");
                }else if (bcBooks.getCartId()!=null){
                    WHERE("cart_id like concat('%',#{bcBooks.cartId},'%')");
                }else if (bcBooks.getMaktAble()!=null){
                    WHERE("makt_able like concat('%',#{bcBooks.maktAble},'%')");
                }
            }
        }.toString();
    }

}
